package com.bh.intercepeor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Base64;
import java.util.Enumeration;

/**
 * @author Wang
 * @version 1.0
 * @date 2022/6/8 20:36
 */
public class AuthInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

//        Enumeration headers=request.getHeaderNames();
//        while (headers.hasMoreElements()){
//            String tmp=headers.nextElement().toString();
//            System.out.println(tmp+"*******"+request.getHeader(tmp));
//        }


                String authorization=request.getHeader("authorization");
        if(null!=authorization){
            String []header=authorization.split("\\s+");
            String rs= new String(Base64.getDecoder().decode(header[1]));
            System.out.println("认证信息:"+rs);
        }

        String token=request.getHeader("x-token");
        System.out.println("token>>>>>"+token);
        return true;
    }
}
